const service = require("../service/user-service");
const { awaitService } = require("../utils/tools");

class UserController {
  // 登录账号处理逻辑
  async findAccount(ctx, next) {
    //获取用户发送请求的参数
    const user = ctx.request.body;
    //对用户数据进行处理
    const result = service.findAccount(user);
    //阻塞一段事件之后再返回
    await awaitService();
    if (result.state === "error") {
      ctx.status = 401;
    }
    ctx.body = result;
  }
  // 手机验证码登录逻辑(使用的仍然是账号数据)
  async findPhone(ctx, next) {
    const user = ctx.request.body;
    console.log(ctx.request.body);
    const result = service.findPhone(user);
    await awaitService();
    if (result.state === "error") {
      ctx.status = 401;
    }
    ctx.body = result;
  }
}

module.exports = new UserController();
